package com.jz.community.moduleexpress.express.ui;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.jz.community.basecomm.base.BaseMvpActivity;
import com.jz.community.basecomm.mvp.BaseMvpPresenter;
import com.jz.community.basecomm.routerUtils.RouterIntentConstant;
import com.jz.community.commview.commPagerAdapter.CommonViewPagerAdapter;
import com.jz.community.moduleexpress.R;
import com.jz.community.moduleexpress.R2;
import com.jz.community.moduleexpress.express.UnclaimedPackageFragment;
import com.jz.community.moduleexpress.express.info.TabEntity;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Created by Tony.Fan on 2018/7/26 14:12
 */
@Route(path = RouterIntentConstant.EXPRESS_HOME)
public class MyExpressActivity extends BaseMvpActivity {

    @BindView(R2.id.express_back)
    ImageView expressBack;
    @BindView(R2.id.express_title)
    TextView expressTitle;
    @BindView(R2.id.express_logistic)
    Button expressLogistic;
    @BindView(R2.id.express_toolbar)
    Toolbar expressToolbar;
    @BindView(R2.id.express_list_tab)
    CommonTabLayout expressListTab;
    @BindView(R2.id.viewpager_express_count)
    ViewPager viewpagerExpressCount;

    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();

    private String title_1 = "待领取";
    private String title_2 = "已签收";

    @Override
    protected void addListener() {
        super.addListener();
        expressBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        expressLogistic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MyExpressActivity.this,ExpressSubmitActivity.class));
            }
        });
    }

    @Override
    protected void initView() {
        super.initView();
        setImmersionBar(expressToolbar);
    }

    @Override
    protected void initDatas() {
        super.initDatas();
        initViewPager();
    }

    @Override
    protected int getContentView() {
        return R.layout.module_express_activity_manger_express;
    }

    private void initViewPager() {
        mTabEntities.add(new TabEntity(title_1));
        mTabEntities.add(new TabEntity(title_2));
        CommonViewPagerAdapter viewPagerAdapter = new CommonViewPagerAdapter(getSupportFragmentManager());
        // 可用
        UnclaimedPackageFragment unclaimedPackageFragment = UnclaimedPackageFragment.newInstance(0);
        viewPagerAdapter.addFragment(unclaimedPackageFragment);
        // 历史
        UnclaimedPackageFragment secondFragment = UnclaimedPackageFragment.newInstance(1);
        viewPagerAdapter.addFragment(secondFragment);
        viewpagerExpressCount.setOffscreenPageLimit(2);
        expressListTab.setTabData(mTabEntities);
        viewpagerExpressCount.setAdapter(viewPagerAdapter);
        viewpagerExpressCount.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                expressListTab.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected BaseMvpPresenter createPresenter() {
        return null;
    }
}
